package core.field;

import core.Player;
import core.PopUpBuy;

public class LaborCamp extends Ownable {
	private int baseRent;
	
	public LaborCamp(String name, int price){
		this.setName(name);
		this.setPrice(price);
	}
	
	public LaborCamp(){
		
	}

	@Override
	public void landOnField(Player player) {
		
		if(owner == null){
			if(new PopUpBuy().BuyFieldQ())
				this.buyField(player);
		}
		if(player != this.owner && this.owner != null){
			int temp;
		temp = 100 * player.getDice()[0].getValue()+player.getDice()[1].getValue() * countLC(owner);
		player.getKonto().withdrawPoints(temp);
		owner.getKonto().addPoints(temp);
		}
			
			
	}

	@Override
	public int getRent() {
		
		return baseRent;
	}
	
	private int countLC(Player player){
		int temp=0;
		
		if(player==null){
			return 0;
		}
		
		for(Field f : player.returnFields()){
			if(f.getClass().equals(new LaborCamp().getClass()))
				temp++;
		}
		return temp;
		
	}

	@Override
	public String subText() {
		String temp = ".";
		if(owner != null){
			temp = owner.getName();
			temp += String.valueOf(getRent());
		}
		else
			temp = String.valueOf(price);
		return temp;
	}
	

}
